import VeeValidate from 'vee-validate';
import zhCn from 'vee-validate/dist/locale/zh_CN';

const dictionary = {
  zhCn: {
    // attributes and messages
    messages: {
      required: (a) => '请填写' + a
    }
  },
  ar: {
    // attributes and messages
  }
};

VeeValidate.Validator.localize(zhCn);
VeeValidate.Validator.localize('zhCn', dictionary.zhCn);
VeeValidate.Validator.localize(dictionary);

//自定义提示语
VeeValidate.Validator.extend('phone', {
  getMessage: field => '手机格式不正确',
  validate: value => {
    return /^1[34578]\d{9}$/.test(value);
  }
});

VeeValidate.Validator.extend('password', {
  getMessage: field => '密码必须为6到20位，且数字和字母组合',
  validate: value => {
    return /^[a-zA-Z]\w{5,19}$/.test(value);
  }
});

export default VeeValidate;
